//
//  MRMUtil.m
//  MeiRiMoney
//
//  Created by qiuqk on 13-7-12.
//  Copyright (c) 2013年 MeiRiCai. All rights reserved.
//

#import "MRMUtils.h"

@implementation MRMUtils

+ (void) setBackButton: (UIViewController *)viewController
{
	[viewController.navigationItem setHidesBackButton:YES];
	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	button.frame = CGRectMake(0, 0, 55, 44);
	[button setBackgroundImage:[UIImage imageNamed:@"light-back-button.png"] forState:UIControlStateNormal];
	
	[button addTarget:viewController action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
	UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithCustomView:button];
	viewController.navigationItem.leftBarButtonItem = backButton;
}

+ (void) setBackButtonWithWapper:(MRMViewControllerWapper *)wapper
{
	[wapper.ViewController.navigationItem setHidesBackButton:YES];
	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	button.frame = CGRectMake(0, 0, 55, 44);
	[button setBackgroundImage:[UIImage imageNamed:@"light-back-button.png"] forState:UIControlStateNormal];
	
	[button addTarget:wapper action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
	UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithCustomView:button];
	wapper.ViewController.navigationItem.leftBarButtonItem = backButton;
}

+ (void) setTopBarTitle: (UIViewController *)viewController title: (NSString *)text
{
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
	label.adjustsFontSizeToFitWidth = YES;
	label.text = text;
	label.textColor = [UIColor orangeColor];
	label.textAlignment = NSTextAlignmentCenter;
	label.font = [UIFont fontWithName:@"Helvetica-Bold" size:22];
	label.backgroundColor = [UIColor clearColor];
	viewController.navigationItem.titleView = label;
}

+ (void) setSettingButton:(UIViewController *)viewController
{
	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	button.frame = CGRectMake(0, 0, 55, 44);
	[button setBackgroundImage:[UIImage imageNamed:@"light-settings-button.png"] forState:UIControlStateNormal];
	
	[button addTarget:viewController action:@selector(showSettingView) forControlEvents:UIControlEventTouchUpInside];
	UIBarButtonItem *aboutButton = [[UIBarButtonItem alloc]initWithCustomView:button];
	viewController.navigationItem.rightBarButtonItem = aboutButton;
}

+ (void) showExchangeCompleteView: (UIViewController *)viewController
{
	UINib *nib = [UINib nibWithNibName:@"MRMExchangeCompleteView" bundle:nil];
	NSArray *views = [nib instantiateWithOwner:self options:nil];
	MRMExchangeCompleteView *view = [views lastObject];
	[view.okButton addTarget:viewController action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
	viewController.view = view;
}

@end
